﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommonFramework.Web;
using Xinkui.Common.Enum;
using Xinkui.Common.FileAction;

namespace Back.Xinkui.WebModel
{
    public class PageAspxBase : PageBase
    {
        protected string BuliderImage(string image, int width, int height, ESourceType sType)
        {
            if (!string.IsNullOrEmpty(image))
            {
                return string.Format(@"<img scr=""{0}"" style=""vertical-align:middle""/>", FileFactory.BrowerFile(image, sType, width, height));
            }
            else
            {
                return @"<img src=""/Themes/default/images/Img/noimage.jpg""  width=""100px;"" style=""vertical-align:middle""/>";
            }
        }


        /// <summary>
        /// 显示消息提示对话框
        /// </summary>
        /// <param name="page">当前页面指针，一般为this</param>
        /// <param name="msg">提示信息</param>
        protected void Show(string msg)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "message", "<script language='javascript' defer>alert('" + msg.ToString() + "');</script>");
        }

        /// <summary>
        /// 控件点击 消息确认提示框
        /// </summary>
        /// <param name="page">当前页面指针，一般为this</param>
        /// <param name="msg">提示信息</param>
        protected void ShowConfirm(System.Web.UI.WebControls.WebControl Control, string msg)
        {
            //Control.Attributes.Add("onClick","if (!window.confirm('"+msg+"')){return false;}");
            Control.Attributes.Add("onclick", "return confirm('" + msg + "');");
        }

        /// <summary>
        /// 显示消息提示对话框，并进行页面跳转window.location
        /// </summary>
        /// <param name="page">当前页面指针，一般为this</param>
        /// <param name="msg">提示信息</param>
        /// <param name="url">跳转的目标URL</param>
        protected void ShowAndRedirect(string msg, string url)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "message", "<script language='javascript' defer>alert('" + msg + "');window.location=\"" + url + "\"</script>");
        }
        /// <summary>
        /// 显示消息提示对话框，并进行页面跳转top.location.href
        /// </summary>
        /// <param name="page">当前页面指针，一般为this</param>
        /// <param name="msg">提示信息</param>
        /// <param name="url">跳转的目标URL</param>
        protected void ShowAndRedirects(string msg, string url)
        {
            StringBuilder Builder = new StringBuilder();
            Builder.Append("<script language='javascript' defer>");
            Builder.AppendFormat("alert('{0}');", msg);
            Builder.AppendFormat("top.location.href='{0}'", url);
            Builder.Append("</script>");
            this.ClientScript.RegisterStartupScript(this.GetType(), "message", Builder.ToString());

        }

        /// <summary>
        /// 输出自定义脚本信息
        /// </summary>
        /// <param name="page">当前页面指针，一般为this</param>
        /// <param name="script">输出脚本</param>
        protected void ResponseScript(string script)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "message", "<script language='javascript' defer>" + script + "</script>");

        }

        /// <summary>
        /// 关闭当前页面并刷新父页面
        /// </summary>
        /// <param name="page"></param>
        /// <param name="msg"></param>
        protected void ShowAndCloseAndReloadOpner(string msg)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "message", "<script language='javascript' defer>alert('" + msg.ToString() + "');opener.location.href=opener.location.href;window.close();</script>");
        }


        /// <summary>
        /// 关闭当前页面并刷新父页面
        /// </summary>
        /// <param name="page"></param>
        /// <param name="msg"></param>
        protected void ShowAndReloadOpner(string msg)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "message", "<script language='javascript' defer>alert('" + msg.ToString() + "');opener.location.href=opener.location.href;window.close();</script>");
        }

        /// <summary>
        /// 提示并关闭当前页
        /// </summary>
        /// <param name="page"></param>
        /// <param name="msg"></param>
        protected void ShowAndClose(string msg)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "message", "<script language='javascript' defer>alert('" + msg.ToString() + "');window.close();</script>");
        }

        /// <summary>
        /// 提示并刷新当前页
        /// </summary>
        /// <param name="page"></param>
        /// <param name="msg"></param>
        protected void ShowAndReload(string msg)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "message", "<script language='javascript' defer>alert('" + msg.ToString() + "');location=location;</script>");
        }

    }
}
